package sn.gandal.mobile.kalpet.utils;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.JavaType;
import org.codehaus.jackson.type.TypeReference;

import sn.gandal.mobile.kalpet.server.dto.AuthDTO;
import sn.gandal.mobile.kalpet.server.dto.CompteCodeDTO;
import sn.gandal.mobile.kalpet.server.dto.CompteCreditDTO;
import sn.gandal.mobile.kalpet.server.dto.CompteGimDTO;
import sn.gandal.mobile.kalpet.server.dto.HistoriqueDTO;


public class Json2JavaParser {
	
	private static AuthDTO authDTO;
	private static CompteCodeDTO compteCode;
	private static CompteCreditDTO compteCredit;
	private static CompteGimDTO compteGIM;
	
	public static AuthDTO parseToAccount (String jsonAccountText){
		AuthDTO authData=null;
		ObjectMapper mapper= new ObjectMapper();
		try {
			authData= mapper.readValue(jsonAccountText, AuthDTO.class);
			
		} catch (JsonParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return authData;
		
	}
	
	@SuppressWarnings("unused")
	private static AuthDTO parseAll (String jsonAccountText){
		AuthDTO authData=null;
		ObjectMapper mapper= new ObjectMapper();
		try {
			authDTO= mapper.readValue(jsonAccountText, AuthDTO.class);
			//compteCode= mapper.readValue(jsonAccountText, CompteCodeDTO.class);
			//compteCredit= mapper.readValue(jsonAccountText, CompteCreditDTO.class);
			//compteGIM= mapper.readValue(jsonAccountText, CompteGimDTO.class);
			
		} catch (JsonParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return authData;
		
	}

	@SuppressWarnings("unused")
	public static List<HistoriqueDTO> parseHistorique (String jsonAccountText){
		List<HistoriqueDTO> authData=null;
		ObjectMapper mapper= new ObjectMapper();

		try {
			authData=  mapper.readValue(jsonAccountText, new TypeReference<List<HistoriqueDTO>>(){});

		} catch (JsonParseException e) {			
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return authData;
		
	}

	
}
